﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrusadeGmTool.Net.IO;

namespace CrusadeGmTool.Net
{
    public class PacketHandler
    {
        int _id;
        int? _length;
        string _name;
        bool _compressed;
        Action<PacketReader> _receiveAction;

        #region Properties

        /// <summary>
        /// Gets the Id of the Packet the handler belongs to.
        /// </summary>
        public int Id
        {
            get { return _id; }
        }

        /// <summary>
        /// Gets the length of the Packet the handler belongs to.
        /// </summary>
        public int? Length
        {
            get { return _length; }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool Compressed
        {
            get { return _compressed; }
        }

        /// <summary>
        /// Gets the name of the Packet the handler belongs to.
        /// </summary>
        public string Name
        {
            get { return _name; }
        }

        /// <summary>
        /// Gets the Action that should be invoked when this handler's packet is received by the ClientNetwork.
        /// </summary>
        public Action<PacketReader> ReceiveAction
        {
            get { return _receiveAction; }
        }
        #endregion

        /// <summary>
        /// Creates a new instance of a PacketHandler
        /// </summary>
        /// <param name="id">The id of the packet the handler responds to.</param>
        /// <param name="name">The name of the packet the handler responds to.</param>
        /// <param name="length">The length of the packet the handler responds to.  
        /// This value should be null if the packet is variable length</param>
        /// <param name="receiveAction">The action to be invoked when the packet is received</param>
        public PacketHandler(int id, string name, int? length, bool compressed, Action<PacketReader> receiveAction)
        {
            _id = id;
            _name = name;
            _length = length;
            _compressed = compressed;
            _receiveAction = receiveAction;
        }
    }
}
